//
//  CYWithdrawSelectCardCell.m
//  cyjf
//
//  Created by tauCross on 2017/5/18.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYWithdrawSelectCardCell.h"

#import <UIImageView+WebCache.h>



@implementation CYWithdrawSelectCardCellObject

@end



@interface CYWithdrawSelectCardCell ()

@property(nonatomic, strong)UIImageView *bankIconImageView;
@property(nonatomic, strong)UILabel *bankNameLabel;
@property(nonatomic, strong)UILabel *cardNumberLabel;
@property(nonatomic, strong)UIImageView *arrow;

@end


@implementation CYWithdrawSelectCardCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.bankIconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 33, 33)];
        self.bankIconImageView.layer.masksToBounds = YES;
        self.bankIconImageView.layer.cornerRadius = self.bankIconImageView.width / 2;
        [self.contentView addSubview:self.bankIconImageView];
        
        self.bankNameLabel = [[UILabel alloc] init];
        self.bankNameLabel.textColor = HEXCOLOR(@"444444");
        self.bankNameLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.bankNameLabel];
        
        self.cardNumberLabel = [[UILabel alloc] init];
        self.cardNumberLabel.textColor = HEXCOLOR(@"999999");
        self.cardNumberLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.cardNumberLabel];
        
        self.arrow = [[UIImageView alloc] initWithImage:CYImage(@"public_cell_arrow")];
        [self.contentView addSubview:self.arrow];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 65;
}

- (BOOL)shouldUpdateCellWithObject:(CYWithdrawSelectCardCellObject *)object
{
    [self.bankIconImageView sd_setImageWithURL:object.bankIcon.tc_url placeholderImage:APP_SQUARE_PLACEHOLDER];
    
    self.bankNameLabel.text = object.bankName;
    
    self.cardNumberLabel.text = object.cardNumber;
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.bankIconImageView.centerY = self.contentView.height / 2;
    self.bankIconImageView.left = 20;
    
    [self.bankNameLabel sizeToFit];
    self.bankNameLabel.left = 62;
    self.bankNameLabel.centerY = 23;
    
    [self.cardNumberLabel sizeToFit];
    self.cardNumberLabel.left = 62;
    self.cardNumberLabel.centerY = 44;
    
    self.arrow.centerY = self.contentView.height / 2;
    self.arrow.right = self.contentView.width - 12;
}

@end
